package com.achievement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.achievement.domain.dto.PaperLevelDTO;
import com.achievement.domain.entity.PaperLevelEntity;
import com.achievement.domain.param.PaperLevelParam;
import com.achievement.domain.vo.PaperLevelVO;
import com.achievement.service.IPaperLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import com.common.core.page.TableDataInfo;

/**
 * 科研成果-刊物级别列Controller
 *
 */
@RestController
@RequestMapping("/achievement/level")
@Api(tags = "成果管理模块---刊物级别")
public class PaperLevelController extends BaseController
{
    @Autowired
    private IPaperLevelService paperLevelService;

    /**
     * 查询科研成果-刊物级别列列表
     */
    @PreAuthorize("@ss.hasPermi('system:level:list')")
    @ApiOperation(value = "列表检索",notes = "列表检索")
    @GetMapping("/list")
    public TableDataInfo list(PaperLevelParam dto) {
        startPage();
        List<PaperLevelVO> list = paperLevelService.selectByPage(dto);
        return getDataTable(list);
    }

    /**
     * 导出科研成果-刊物级别列列表
     */
    @PreAuthorize("@ss.hasPermi('system:level:export')")
    @Log(title = "科研成果-刊物级别列", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "刊物级别导出",notes = "刊物级别导出")
    @PostMapping("/export")
    public void export(HttpServletResponse response, PaperLevelDTO dto) {
        List<PaperLevelEntity> list = paperLevelService.getListByConditions(dto);
        ExcelUtil<PaperLevelEntity> util = new ExcelUtil<>(PaperLevelEntity.class);
        util.exportExcel(response, list, "科研成果-刊物级别列数据");
    }

    /**
     * 获取科研成果-刊物级别列详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:level:query')")
    @ApiOperation(value = "获取刊物级别详细信息",notes = "获取刊物级别详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(paperLevelService.getInfoById(id));
    }

    /**
     * 新增科研成果-刊物级别列
     */
    @PreAuthorize("@ss.hasPermi('system:level:add')")
    @Log(title = "科研成果-刊物级别列", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增科研成果-刊物级别列",notes = "新增科研成果-刊物级别列")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody PaperLevelDTO dto) {
        String result = paperLevelService.add(dto);
        return StringUtils.isNotEmpty(result) ? success((Object) result) : error();
    }

    /**
     * 修改科研成果-刊物级别列
     */
    @PreAuthorize("@ss.hasPermi('system:level:edit')")
    @Log(title = "科研成果-刊物级别列", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改刊物级别",notes = "修改刊物级别")
    @PostMapping(value = "/update")
    public AjaxResult edit(@RequestBody PaperLevelDTO dto)
    {
        return toAjax(paperLevelService.update(dto));
    }

    /**
     * 删除科研成果-刊物级别列
     */
    @PreAuthorize("@ss.hasPermi('system:level:remove')")
    @Log(title = "科研成果-刊物级别列", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除刊物级别",notes = "删除刊物级别")
	@DeleteMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids) {
        return toAjax(paperLevelService.batchRemove(ids));
    }
}
